//
//  CQStatusCell.swift
//  weibo
//
//  Created by chengqiang on 16/7/24.
//  Copyright © 2016年 chengqiangBiaodashi. All rights reserved.
//

import UIKit
import SnapKit
class CQStatusCell: UITableViewCell {
    
    //bottonview的顶部约束
    var bottonViewCons : Constraint?
    
    var status:CQstatus?{
        didSet{
            origialView.status=status
            
            retweenView.retweetStatus = status?.retweeted_status
            //删除之前的约束
            bottonViewCons?.uninstall()
            if status?.retweeted_status == nil{
                retweenView.hidden = true
                bottomView.snp_makeConstraints(closure: { (make) in
                    bottonViewCons = make.top.equalTo(origialView.snp_bottom).constraint
                })
                
            }else{
                retweenView.hidden = false
                bottomView.snp_makeConstraints(closure: { (make) in
                    bottonViewCons = make.top.equalTo(retweenView.snp_bottom).constraint
                })
            }
        }
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        setupUI()
    }
    
    
    //设置界面
    private func setupUI(){
        self.contentView.backgroundColor=UIColor(white: 237.0/255.0, alpha: 1)
        
        self.contentView.addSubview(origialView)
        self.contentView.addSubview(retweenView)
        self.contentView.addSubview(bottomView)
        
            
        origialView.snp_makeConstraints { (make) in
            make.leading.trailing.equalTo(self.contentView)
            make.top.equalTo(self.contentView).offset(8)
        }
        
        retweenView.snp_makeConstraints { (make) in
            make.leading.trailing.equalTo(self.contentView)
            make.top.equalTo(origialView.snp_bottom)
        }
        
        bottomView.snp_makeConstraints { (make) in
            make.leading.trailing.equalTo(self.contentView)
//            make.top.equalTo(retweenView.snp_bottom)
            bottonViewCons = make.top.equalTo(retweenView.snp_bottom).constraint
            
            make.height.equalTo(37)
        }
        
        self.contentView.snp_makeConstraints { (make) in
            make.leading.top.trailing.equalTo(self)
        }
        
        self.contentView.snp_makeConstraints { (make) in
            make.bottom.equalTo(bottomView)
        }
        
     
    
    }
    
    private lazy var origialView:CQStatusView = CQStatusView()
    private lazy var bottomView:CQstatusBottomView = CQstatusBottomView()
    private lazy var retweenView:CQStatusRetweetView = CQStatusRetweetView()
}
